from time import sleep

import page
from base.base import Base
from tool.get_log import GetLogger

log = GetLogger().get_log()


class PageJiamingceshi(Base):

    def pagejiamingceshi_click_wsy_tab(self):
        self.base_click_element(page.wsy_tab)

    def pagejiamingceshi_click_start_study(self):
        self.base_click_element(page.wsy_start_study)

    def pagejiamingceshi_click_ceshi(self):
        self.base_click_element(page.study_1_ceshi)

    def pagejiamingceshi_get_ans(self):
        self.base_get_question_answer(page.study1_question, page.study1_ans)

    def pagejiamingceshi_click_fixed_answer(self):
        self.base_click_element(page.study1_ans)

    def pagejiamingceshi_click_confirm(self):
        self.base_click_element(page.study1_confirm)

    def pagejiamingceshi_click_next_question(self):
        self.base_click_element(page.study1_next)

    def pagejiamingceshi_if_confirm_exist(self):
        return self.base_if_element_exist(page.study1_confirm)

    def pagejiamingceshi_if_question_exist(self):
        return self.base_if_element_exist(page.study1_question)

    def pagejiamingceshi_if_next_question_exist(self):
        return self.base_if_element_exist(page.study1_next)

    def pagejiamingceshi_return_to_wsypage_keycode(self):
        for a in range(10):
            log.info(f'正在返回五十音页面，第{a + 1}次尝试')
            if self.base_if_element_exist(page.wsy_tab):
                break
            else:
                self.driver.press_keycode(4)

    def pagejiamingceshi_click_share_report_back(self):
        self.base_click_element(page.study1_report_back)
        self.base_click_element(page.study1_wuxingtanchuang_close)

    def pagejiamingceshi_if_unlocked_success(self):
        if self.base_if_element_exist(page.study2_locked):
            return False
        else:
            return True

    def pagejiamingceshi_fuxi(self):
        self.base_click_element(page.wsy_zixuanfuxi)
        self.base_click_element(page.fuxi_1)
        self.base_click_element(page.fuxi_1_start)
        sleep(30)

    def pagewsy_click_banner(self):
        self.base_click_element(page.wsy_ad)

    def pagewsy_click_report_ad(self):
        self.base_click_element(page.study1_ad)
